<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
<div id="app">
    <mytag title="第一个组件" @clicknow="showClickTimes"><p>通过slot在这里添加tag</p></mytag>
    <mytag title="第二个组件"></mytag>
</div>
    
<script>
    // 注册组件
    Vue.component("mytag", {
        props: ['title'],
        data: function(){
            return {
                count: 0
            }
        },
        methods: {
            clickfun: function(){
                this.count++
                this.$emit('clicknow',this.count)
            }
        },
        template:'<div><button @click="clickfun">{{title}} 点击：{{count}} times<slot></slot></button></div>'
    })
    // 实例化Vue
    var app = new Vue({
        el: "#app",
        data: {},
        methods: {
            showClickTimes: function(e){
                console.log(e);
            }
        }
    })
</script>
</body>
</html>